<!-- 自定义标准图表 设置百分百宽度 通过平台组件来适配尺寸 可以替换数据以及设置高级属性自定义扩展 详细查看组件示例.txt
  注:如需设置图片存放文件夹名称需应与当前文件名一致(1并在aircim.webpack.build.component.config.js配置需要打包的文件 2.npm run lib_c 执行打包命令  最后的组件会打包在components/grids中)-->
<template>
  <div class="scale-box" :id="dynamicIdName()">
    <div
        class="service-efficiency-box animate__animated"
        :class="dynamicClassName"
        style="width: 460px;height: 537px;"
        :id="dynamicChildName()"
    >
      <h1 class="h1_title">
        <span>能力评估</span>
      </h1>
      <div class="power-panel">
        <div>
          <span :class="{'active': activeIndex === 0}" @click="activeIndex = 0">服务能力</span>
          <span :class="{'active': activeIndex === 1}" @click="activeIndex = 1">服务质量</span>
        </div>
        <div>
          <span :class="{'active': activeIndex === 2}" @click="activeIndex = 2">服务便捷度</span>
          <span :class="{'active': activeIndex === 3}" @click="activeIndex = 3">服务效率</span>
        </div>
      </div>
      <div class="panel-content" >
        <div class="panel-content-title">{{ panelList[activeIndex].title }}</div>
        <ul class="panel-content-list">
          <li class="panel-content-list-item" :class="'item'+(activeIndex+1)" v-for="(item,index) in panelList[activeIndex].list" :key="index">
            <span class="item-content">
              <em>{{ item.value }}</em>%
            </span>
            <span class="item-title omit">{{ item.name }}</span>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>
<script>
//引入封装方法
import encapsulation from "../../utils/aircimGird";
import BarHorizontal from "./BarHorizontal.vue";
export default {
  //混入封装方法
  mixins: [encapsulation],
  data: function() {
    return {
      resizeObserver: null,
      //动态Id
      timestamp: null,
      activeIndex:0,
      panelList:[
        {
          title:'服务能力',
          list:[
            {
              name:'网上服务成效率',
              value:'98.23'
            },
            {
              name:'网上服务满意率',
              value:'98.23'
            },
            {
              name:'电子证照应用率',
              value:'98.23'
            }
          ]
        },
        {
          title:'服务质量',
          list:[
            {
              name:'网上服务成效率',
              value:'98.23'
            },
            {
              name:'网上服务满意率',
              value:'98.23'
            },
            {
              name:'电子证照应用率',
              value:'98.23'
            }
          ]
        },
        {
          title:'服务便捷度',
          list:[
            {
              name:'网上服务成效率',
              value:'98.23'
            },
            {
              name:'网上服务满意率',
              value:'98.23'
            },
            {
              name:'电子证照应用率',
              value:'98.23'
            }
          ]
        },
        {
          title:'服务效率',
          list:[
            {
              name:'网上服务成效率',
              value:'98.23'
            },
            {
              name:'网上服务满意率',
              value:'98.23'
            },
            {
              name:'电子证照应用率',
              value:'98.23'
            }
          ]
        },
      ]
    };
  },
  mounted() {
    this.timestamp = new Date().getTime();
    this.$nextTick(() => {
      // 监听盒子变化
      this.listenChangeFn();
    });
  },
  methods: {
    //监听外部盒子的大小 然后对数据井行缩放
    scaleFn() {
      const parentBox = document.getElementById(`dynamic-${this.timestamp}`);
      const childBox = document.getElementById(
          `dynamicChild-${this.timestamp}`
      );
      const parentWidth = parentBox.offsetWidth;
      const parentHeight = parentBox.offsetHeight;
      const childWidth = childBox.offsetWidth;
      const childHeight = childBox.offsetHeight;
      let scaleX, scaleY;
      if (parentWidth < childWidth || parentHeight < childHeight) {
        const scaleBasedOnWidth = parentWidth / childWidth;
        const scaleBasedOnHeight = parentHeight / childHeight;
        scaleX = scaleBasedOnWidth;
        scaleY = scaleBasedOnHeight;
      } else {
        scaleX = parentWidth / childWidth;
        scaleY = parentHeight / childHeight;
      }
      childBox.style.transform = `scale(${scaleX}, ${scaleY})`;
    },
    // 监听盒子变化
    listenChangeFn() {
      let that = this;
      const element = document.getElementById(`dynamic-${this.timestamp}`);
      // console.log(element, "element");
      if (element) {
        new ResizeObserver(() => {
          // 处理元素大小变化的逻辑
          that.scaleFn();
        }).observe(element);
      }
    },
    // 绑定动画样式 animate__flash
    bindAnimationFn(animateName) {
      if (animateName != null) {
        this.dynamicClassName = animateName;
      }
    },
    //定义唯一ID名
    dynamicIdName() {
      return `dynamic-${this.timestamp}`;
    },
    //定义唯一ID名
    dynamicChildName() {
      return `dynamicChild-${this.timestamp}`;
    },
  },
  // 销毁监听
  beforeDestroy() {
    // 组件销毁前停止监听
    if (this.resizeObserver) {
      this.resizeObserver.disconnect();
    }
    if (this.requestTime != null) {
      clearInterval(this.requestTime);
    }
  },
};
</script>
<style lang="scss" scoped>
@import "../../static/assets/common.scss";
</style>
<style lang="scss" scoped>
.scale-box {
  width: 100%;
  height: 100%;
}

.service-efficiency-box {
  position: absolute;
  padding: 0 20px;
  box-sizing: border-box;
  overflow: hidden;
  transform-origin: left top;
  background-image: url(../../../thumbnail/backImg/new-border-mini-green.png);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  color: #fff;
}

.power-panel{
  margin-top: -15px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 56px;
  width: 100%;
  height: 235.819px;
  background: url(../../static/assets/AssessPower/power_bg.png) no-repeat center center;
  background-size: cover;
  div{
    display: flex;
    justify-content: space-between;
    width: 100%;
  }
  span{
    display: flex;
    justify-content: center;
    align-items: center;
    width: 98px;
    height: 31px;
    font-family: "Source Han Sans CN";
    cursor: pointer;
    &.active{
      color: #0FF;
      font-size: 16px;
      font-weight: 700;
    }
  }
}

.panel-content{
 width: 100%;
  display: flex;
  align-items: center;
  flex-direction: column;
  height: 232px;
  margin-top: 22px;
  padding: 15px 18px 0;
  background: url(../../static/assets/AssessPower/panel_bg.png) no-repeat center center;
  background-size: cover;

  &-title{
    position: relative;
    width: fit-content;
    height: 27px;
    color: #FFF;
    font-family: "Source Han Sans CN";
    font-size: 18px;
    font-weight: 700;
    text-align: center;
    &::before{
      position: absolute;
      content: "";
      top: 50%;
      left: -10px;
      transform: translate(-100%,-100%);
      width: 11px;
      height: 6px;
      background: url(../../static/assets/AssessPower/icon.png) no-repeat center center;
      background-size: 100% 100%;
    }
    &::after{
      position: absolute;
      content: "";
      top: 50%;
      right: -10px;
      transform: translate(100%,-100%);
      width: 11px;
      height: 6px;
      background: url(../../static/assets/AssessPower/icon.png) no-repeat center center;
      background-size: 100% 100%;
    }
  }

  &-list{
    width: 100%;
    height: 140px;
    display: flex;
    justify-content: space-between;
    gap: 24px;
    margin-top: 19px;
    &-item{
      width: 112px;
      height: 140px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      align-items: center;
      background-repeat: no-repeat;
      background-position: center center;
      background-size: 82px 76px;
      .item-content{
        color: #96BEE0;
        font-family: "Source Han Sans CN";
        font-size: 14px;
        font-weight: 400;
        em{
          color: #0FF;
          text-align: center;
          font-family: D-DIN;
          font-size: 24px;;
          font-weight: 700;
        }
      }
      .item-title{
        width: 100%;
        text-align: center;
        color: #FFF;
        font-family: "Source Han Sans CN";
        font-size: 16px;
        font-weight: 400;
      }
    }
  }
}
.item1{
   &:nth-child(1){
     background-image: url(../../static/assets/AssessPower/power1_icon1.png);
   }
   &:nth-child(2){
     background-image: url(../../static/assets/AssessPower/power1_icon2.png);
   }
   &:nth-child(3){
     background-image: url(../../static/assets/AssessPower/power1_icon3.png);
   }
 }
.item2{
  &:nth-child(1){
    background-image: url(../../static/assets/AssessPower/power2_icon1.png);
  }
  &:nth-child(2){
    background-image: url(../../static/assets/AssessPower/power2_icon2.png);
  }
  &:nth-child(3){
    background-image: url(../../static/assets/AssessPower/power2_icon3.png);
  }
}
.item3{
  &:nth-child(1){
    background-image: url(../../static/assets/AssessPower/power3_icon1.png);
  }
  &:nth-child(2){
    background-image: url(../../static/assets/AssessPower/power3_icon2.png);
  }
  &:nth-child(3){
    background-image: url(../../static/assets/AssessPower/power3_icon3.png);
  }
}
.item4{
  &:nth-child(1){
    background-image: url(../../static/assets/AssessPower/power4_icon1.png);
  }
  &:nth-child(2){
    background-image: url(../../static/assets/AssessPower/power4_icon2.png);
  }
  &:nth-child(3){
    background-image: url(../../static/assets/AssessPower/power4_icon3.png);
  }
}
// 单行省略
.omit {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

</style>
